package com.example.clublesson01.fragments

import android.app.AlertDialog
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.bw.kf.lib_base.base.BaseViewActivity
import com.bw.kf.lib_base.base.BaseViewFragment
import com.example.clublesson01.R
import com.example.clublesson01.databinding.FragmentMineBinding
import okhttp3.Route

class MineFragment : BaseViewFragment<FragmentMineBinding>() {

    //SPUtils.getInstance().put("token",it.data.access_token)

    override fun iniView() {
        val token = SPUtils.getInstance().getString("token").toString()
        if(token.isNullOrEmpty()){
            binding.tvLogin.visibility=View.VISIBLE
            binding.ll.visibility=View.GONE
            binding.tvLogin.text="未登录"
        }else{
            binding.tvLogin.visibility=View.GONE
            binding.ll.visibility=View.VISIBLE
            binding.loginName.text="摩友"+token
        }
        binding.ll.setOnClickListener {
            AlertDialog.Builder(context)
                .setTitle("提示") // 设置标题
                .setMessage("确定要退出登录吗？") // 设置消息内容
                .setPositiveButton("确定") { dialog, which ->
                    // 确定按钮点击事件
                    SPUtils.getInstance().put("token","")
                   ToastUtils.showLong("退出登录了")
                    val token1 = SPUtils.getInstance().getString("token").toString()
                    if(token1.isNullOrEmpty()){
                        binding.tvLogin.visibility=View.VISIBLE
                        binding.ll.visibility=View.GONE
                        binding.tvLogin.text="未登录"
                    }else{
                        binding.tvLogin.visibility=View.GONE
                        binding.ll.visibility=View.VISIBLE
                        binding.loginName.text="摩友"+token
                    }
                }
                .setNegativeButton("取消") { dialog, which ->
                    // 取消按钮点击事件
                    ToastUtils.showLong("取消了")
                }
                .setCancelable(false) // 设置是否可以通过点击外部或返回键取消
                .show()
        }
        binding.tvLogin.setOnClickListener {

            ARouter.getInstance().build("/app/login/LoginPhoneActivity").navigation()
        }
    }

    override fun iniData() {

    }

    override fun Layoutid(): Int {

         return R.layout.fragment_mine
    }

}


